﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using BUSAuction;
using DTOAuction;

namespace _HTTT_HD_QuanLyGiaoDuc_WebService
{
	/// <summary>
	/// Summary description for ServiceDangKyHocPhan
	/// </summary>
	[WebService(Namespace = "http://tempuri.org/")]
	[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
	[System.ComponentModel.ToolboxItem(false)]
	// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
	// [System.Web.Script.Services.ScriptService]
	public class ServiceDangKyHocPhan : System.Web.Services.WebService
	{
		/// <summary>
		/// author: hqlam
		/// </summary>
		[WebMethod]
		public bool dangKyHocPhan(int maSinhVien, int maLop)
		{
			bool res = true;
			try
			{
				ServiceXuLyThongTinSinhVien svService = new ServiceXuLyThongTinSinhVien();
				if (!svService.kiemTraThongTinSinhVien(maSinhVien)) return false;

				ServiceXuLyThongTinLop lopService = new ServiceXuLyThongTinLop();
				if (!lopService.kiemTraThongTinLopHoc(maLop)) return false;

				ServiceXuLyThongTinDangKy ttdkService = new ServiceXuLyThongTinDangKy();
				if (!ttdkService.kiemTraThoiHanDangKyHocPhan(DateTime.Now)) return false;
				if (!ttdkService.kiemTraThongTinDangKy(maSinhVien, maLop)) return false;

				ttdkService.ghiNhanThongTinDangKyCuaSinhvien(maSinhVien, maLop);

				LOP lop = lopService.layThongTinLop(maLop);
				lop.SLSVDK_CHINHTHUC++;
				lopService.capNhatThongTinLopHoc(lop);
				return true;
			}
			catch
			{
				res = false;
			}
			return res;
		}

		/// <summary>
		/// author: hqlam
		/// </summary>
		[WebMethod]
		public bool huyDangKy(int maSinhVien, int maLop)
		{
			bool res = true;
			try
			{
				// xoa thong tin dang ky
				BUSThongTinDangKy.huyDangKy(maSinhVien, maLop);

				// cap nhat si so lop
				ServiceXuLyThongTinLop lopService = new ServiceXuLyThongTinLop();
				LOP lop = lopService.layThongTinLop(maLop);
				if (lop.SLSVDK_CHINHTHUC > 0)
				{
					lop.SLSVDK_CHINHTHUC--;
					lopService.capNhatThongTinLopHoc(lop);
				}
				return true;
			}
			catch
			{
				res = false;
			}
			return res;
		}

	}
}
